package com.web.servlet.db;

import java.sql.Types;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import com.web.servlet.utils.TimeServerUtil;


public class LogDaoImpl extends StrategyBaseDao implements LogDao {

	

	/*@Override
	public boolean addItemLog(List<ItemLog> infos) {
		if (infos == null || infos.size() == 0)
			return true;
		List<String> sqlComm = new ArrayList<String>();
		for (ItemLog info : infos) {
			if (info != null) {
				sqlComm.add(String.format(
						" INSERT INTO log_item(player_id,item_id,change_id,change_itemnum,now_nownum,change_date) "
								+ "VALUE (%s,%s,%s,%s,%s,'%s')", info.getPlayerID(), info.getItemID(), info
								.getChangeID(), info.getChangeItemNum(), info.getNowItemNum(), info.getChangeDate()));
			}
		}
		return sqlBatch("log_item", sqlComm);
	}*/

	@Override
	public boolean addLoginLog(long playerId, int isNewPlayer,String channel) {
		if (playerId == 0) {
			return false;
		}
		boolean result = false;
			String sql = " INSERT INTO log_login(`playerId`, `is_new`, `login_time`, `channel`)  VALUES(?,?,?,?);";
			Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
			para.put(1, new DbParameter(Types.INTEGER, playerId));
			para.put(2, new DbParameter(Types.INTEGER, isNewPlayer));
			para.put(3, new DbParameter(Types.TIMESTAMP, TimeServerUtil.getSysteCurTime()));
			para.put(4, new DbParameter(Types.VARCHAR, channel));
			result = execNoneQuery(sql, para) > -1 ? true : false;
		
		return result;
	}

	@Override
	public boolean addChargeLog(long playerId, int chargeNum, int chargeType,String channel) {
		if (playerId == 0) {
			return false;
		}
		boolean result = false;
			String sql = " INSERT INTO log_charge(`playerId`, `charge_num`, `charge_type`, `create_date`, `channel`)  VALUES(?,?,?,?,?);";
			Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
			para.put(1, new DbParameter(Types.INTEGER, playerId));
			para.put(2, new DbParameter(Types.INTEGER, chargeNum));
			para.put(3, new DbParameter(Types.INTEGER, chargeType));
			para.put(4, new DbParameter(Types.TIMESTAMP, TimeServerUtil.getSysteCurTime()));
			para.put(5, new DbParameter(Types.VARCHAR, channel));
			result = execNoneQuery(sql, para) > -1 ? true : false;
		
		return result;
	}

	@Override
	public boolean addOnlineLog(int onlineNum) {
		boolean result = false;
			String sql = " INSERT INTO log_online(`oline_num`, `create_time`)  VALUES(?,?);";
			Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
			para.put(1, new DbParameter(Types.INTEGER, onlineNum));
			para.put(2, new DbParameter(Types.TIMESTAMP, TimeServerUtil.getSysteCurTime()));
			result = execNoneQuery(sql, para) > -1 ? true : false;
		
		return result;
	}

	@Override
	public boolean addPlayerNum(Date timeNow, int num) {
		boolean result = false;
		String sql = " INSERT INTO log_playernum(`player_num`, `create_date`)  VALUES(?,?);";
		Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
		para.put(1, new DbParameter(Types.INTEGER, num));
		para.put(2, new DbParameter(Types.TIMESTAMP, timeNow));
		result = execNoneQuery(sql, para) > -1 ? true : false;
	
	return result;
	}

	
	
	
}
